package com.sqx.modules.pay.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sqx.common.utils.Result;
import com.sqx.modules.pay.dao.PayClassifyDao;
import com.sqx.modules.pay.entity.PayClassify;
import com.sqx.modules.pay.service.PayClassifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class PayClassifyServiceImpl  extends ServiceImpl<PayClassifyDao, PayClassify> implements PayClassifyService {
    @Autowired
    private PayClassifyDao payClassifyDao;
    @Override
    public Result selectPayClassifyList() {
        LambdaUpdateWrapper<PayClassify> payClassifyLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        payClassifyLambdaUpdateWrapper.eq(PayClassify::getStatus,1);
        return Result.success().put("data",payClassifyDao.selectList(payClassifyLambdaUpdateWrapper));
    }

    @Override
    public Result selectPayClassifyById(Integer payClassifyId) {
        LambdaUpdateWrapper<PayClassify> payClassifyLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        payClassifyLambdaUpdateWrapper.eq(PayClassify::getPayClassifyId,payClassifyId);
        payClassifyLambdaUpdateWrapper.eq(PayClassify::getStatus,1);
        return Result.success().put("data",payClassifyDao.selectOne(payClassifyLambdaUpdateWrapper));
    }

    @Override
    public void updatePayClassify(PayClassify payClassify) {
        payClassifyDao.updateById(payClassify);
    }

    @Override
    public void deletePayClassify(Integer[] payClassifyIds) {
        LambdaUpdateWrapper<PayClassify> payClassifyLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        payClassifyLambdaUpdateWrapper.in(PayClassify::getPayClassifyId,payClassifyIds);
        payClassifyLambdaUpdateWrapper.set(PayClassify::getStatus,2);
        payClassifyLambdaUpdateWrapper.set(PayClassify::getDeleteTime,new Date());
        payClassifyDao.update(null,payClassifyLambdaUpdateWrapper);
    }

    @Override
    public void addPayClassify(PayClassify payClassify) {
        payClassify.setCreateTime(new Date());
        payClassifyDao.insert(payClassify);
    }
}
